#include <gtk/gtk.h>
#include <stdio.h>

#include "gtkutils.h"

void sayHello() {
    printf("hello word\n");
}

GtkImage *image;
GdkPixbuf *pixbuf;

createSignalFunc(update_image) {

    GError *error = NULL;
    const char *text = entryGetText(user_data);
    
    if ((pixbuf = createPixbuferFromFile(text, &error)) != NULL) {
        gtk_image_set_from_pixbuf(image, pixbuf);
    }
    
    // if((image = createImageFromFile(text)) != NULL) {
    // }

}

createSignalFunc(on_paste) {
    printf("paste....\n");
}

static void activate(GtkApplication *app, gpointer user_data) {
    GtkWindow *window;

    window = createWindowWithTitleSize(app, "gtk-image-file-test", 200, 100);
    
    GtkEntry *entry = createEntry();
    // connectTargetAction(entry, entry, "paste-clipboard", on_paste);

    image = createImage();

    GtkBox *input_ctl_box = createBoxWithHorizntalAppends(5, 
        createLabel("图片路径:"),
        entry,
        createButtonAction(entry, "确定", update_image),
        NULL
    );
    setBoxHorizntalAlign(input_ctl_box, ACENTER);

    GtkBox *mainbox = createBoxWithVerticalAppends(5, 
        input_ctl_box,
        image,
        NULL
    );

    setWindowChild(window, mainbox);
    showWindow(window);
}

int	main(int argc, char **argv) {

    GtkApplication *app;
    int status;

    app = createApplicationConnectActivate("gtk.example.template", 
                                G_APPLICATION_FLAGS_NONE, activate);
    // app = gtk_application_new("gtk.example.template", G_APPLICATION_FLAGS_NONE);
    // g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    // status = g_application_run(G_APPLICATION(app), argc, argv);
    // g_object_unref(app);
    status = runApplication(app, argc, argv);
    objectUnref(app);

    return status;
}

